package main

import "fmt"

// 产品接口
type Vehicle interface {
	Drive()
}

// 产品实现
type Car struct{}

func (c *Car) Drive() {
	fmt.Println("Driving a car.")
}

type Bike struct{}

func (b *Bike) Drive() {
	fmt.Println("Riding a bike.")
}

// 工厂接口
type VehicleFactory interface {
	CreateVehicle() Vehicle
}

// 具体工厂
type CarFactory struct{}

func (cf *CarFactory) CreateVehicle() Vehicle {
	return &Car{}
}

type BikeFactory struct{}

func (bf *BikeFactory) CreateVehicle() Vehicle {
	return &Bike{}
}

func main() {
	carFactory := &CarFactory{}
	bikeFactory := &BikeFactory{}

	car := carFactory.CreateVehicle()
	bike := bikeFactory.CreateVehicle()

	car.Drive()  // 输出: Driving a car.
	bike.Drive() // 输出: Riding a bike.
}
